# coding=utf-8
# _*_ coding:utf-8 _*_
from  SplitGraph  import SplitGraph
from  ImageServer  import ImageServer
from  ArgvParamet import ArgvParamet
from  HttpServer import HttpServer
import  sys,json , codecs,os
if __name__ == '__main__': 
    
    if len(sys.argv) > 1:
        obj = ArgvParamet(sys.argv).obj
        if obj.get('h') == '?':
            print('--h                         Help')
            print('--save          Storage location')
            print('--img         Large map position')
            print('--OrgnalImgFile        traversal paths')
            print('--SaveFile          Storage path')
            print('--blank                      no')
            print('--MaxValue                   1920')
        elif obj.get('save') != None and obj.get('img') != None:
            SplitGraph(obj)
        elif obj.get('OrgnalImgFile') != None and obj.get('SaveFile') != None:
            ImageServer(obj)
    else:
        f = codecs.open("config.json",encoding='utf-8')
        _str = f.read()
        f.close()
        config = json.loads(_str)
        if config.get('OrgnalImgFile'):
            config.update({'OrgnalImgFile':os.path.abspath(config.get('OrgnalImgFile'))})
        
        if config.get('SaveFile'):
            config.update({'SaveFile':os.path.abspath(config.get('SaveFile'))})
        M=ImageServer(config)
        HttpServer(M,config)

        # pyinstaller --console --onefile main.py -F -i "favicon.ico"
